package com.active.fnd.arch.wizard.model
{
	import flash.events.EventDispatcher;

	import mx.core.ClassFactory;
	import mx.core.UIComponent;
	import mx.events.FlexEvent;

	[Bindable]
	public class Step
	{
		public var name:String;
		public var viewClass:Class;
		public var pmClass:Class;

		public var showBottomBar:Boolean;
		public var showBack:Boolean;
		public var isContinue:Boolean;

		public function Step(name:String, pmClass:Class, viewClass:Class, showBottomBar:Boolean, showBack:Boolean, isContinue:Boolean)
		{
			this.name=name;
			if (pmClass)
			{
				this.pmClass=pmClass;
			}
			else
			{
				this.pmClass=NULLStepPM;
			}
			this.viewClass=viewClass;
			this.showBottomBar=showBottomBar;
			this.showBack=showBack;
			this.isContinue=isContinue;
		}

		public function createPM():StepPM
		{
			var myClassFactory:ClassFactory=new ClassFactory(pmClass);
			var pm:StepPM=myClassFactory.newInstance();
			pm.addToPMContext();
			return pm;
		}

		public function createView():UIComponent
		{
			var backShowBottomBar:Boolean=showBottomBar;
			showBottomBar=false;
			var myClassFactory:ClassFactory=new ClassFactory(viewClass);
			var view:UIComponent=myClassFactory.newInstance();
			view.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
			function creationCompleteHandler(event:Object):void
			{
				//Hide bottom bar, display it when creation complete
				showBottomBar=backShowBottomBar;
				view.removeEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
			}
			return view;
		}
	}
}